package com.agriculture.monitor.controller;

import com.agriculture.monitor.base.ResultInfo;
import com.agriculture.monitor.dto.PositionPage;
import com.agriculture.monitor.dto.ValueLabelTree;
import com.agriculture.monitor.entity.Position;
import com.agriculture.monitor.service.IPositionService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Log4j2
@RestController
@RequestMapping("/position")
public class PositionController {


    @Autowired
    IPositionService positionService;

    @ApiOperation(value = "地址保存", notes = "地址保存")
    @PostMapping("/save")
    public ResultInfo<?> saveData(@RequestBody Position position) {
        return ResultInfo.OK(positionService.saveData(position));
    }

    @ApiOperation(value = "查询", notes = "查询")
    @PostMapping("/page")
    public ResultInfo<?> page(@RequestBody PositionPage position) {
        return ResultInfo.OK(positionService.listPage(position));
    }

    @ApiOperation(value = "删除", notes = "删除")
    @PostMapping("/delete")
    public ResultInfo<?> remove(@RequestBody Position position) {
        return ResultInfo.OK(positionService.removeById(position.getId()));
    }

    @ApiOperation(value = "树接口", notes = "树接口")
    @GetMapping("/tree")
    public ResultInfo<List<ValueLabelTree>> tree() {
        return ResultInfo.OK(positionService.tree());
    }
}
